package view.bullet
{

	import data.Globals;
	
	import flash.display.Sprite;
	import flash.geom.Point;
	
	import manager.ObjectPool;
	
	import utils.GameUtils;
	import utils.HitTest;
	

	public class BaseBullet extends Sprite
	{
		public var onRemove:Function;
		
		private var _ART:int = 3;
		
		private var _speed:int;
		
		private var xSpeed:int;
		
		private var ySpeed:int;
		
		private var _tarPoint:Point;
		
		private var monterAry:Array = Globals.gameView.getMonsterAry();
	
		public function BaseBullet()
		{
			super();
		}
		
		public function move():void{
			this.x += xSpeed;
			this.y += ySpeed;
			checkIsOutBorder();
		}
	
		private function checkIsOutBorder():void
		{
			if(this.x<0||this.x>Globals.stage_width||this.y<0||this.y>Globals.stage_height){
				remove();
			}
		}
		
		private function remove():void{
			if(this.parent){
				this.parent.removeChild(this);
				ObjectPool.putObj(this);
				onRemove(this);
			}
		}
		
		public function checkHitMonster():void{
			var i:int = 0;
			for(i;i<monterAry.length;i++){
				if(HitTest.complexHitTestObject(monterAry[i],this)){
					monterAry[i].blood -= ART;
					remove();
					return;
				}
			}
		}
		public function get speed():int
		{
			return _speed;
		}

		public function set speed(value:int):void
		{
			_speed = value;
			var p:Point = GameUtils.getSpeed(new Point(this.x,this.y),new Point(tarPoint.x,tarPoint.y),value);
			xSpeed = p.x;
			ySpeed = p.y;
		}

		/**
		 *攻击力 
		 */
		public function get ART():int
		{
			return _ART;
		}

		/**
		 * @private
		 */
		public function set ART(value:int):void
		{
			_ART = value;
		}

		/**
		 * 目标点坐标 
		 */
		public function get tarPoint():Point
		{
			return _tarPoint;
		}

		/**
		 * @private
		 */
		public function set tarPoint(value:Point):void
		{
			_tarPoint = value;
			this.rotation = GameUtils.getRotation(new Point(this.x,this.y),value);
		}

	}
}